//
//  LoggedCell.m
//  OrderSeat
//
//  Created by haiming on 13-10-7.
//  Copyright (c) 2013年 wangwei. All rights reserved.
//

#import "LoggedCell.h"
#import "UIImageView+WebCache.h"


#define kUSERINFO   1001
#define kLINEIMAGE  5001
#define kICON       2001
#define kLABEL      2002    
#define kMEUSER     1002
#define kUSERAVATER    3001
#define kUSERNAME       3002
#define kINTERGRATION   3003
#define kTEL            3004

@implementation LoggedCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void) setUpUI:(int)row//logged
{
    if (row == 0){
        UIView *view = (UIView *)[self viewWithTag:kUSERINFO];
        [view drawBorderWidth:1];
    }
    UIImageView *lineImageView = (UIImageView *)[self viewWithTag:kLINEIMAGE];
    if (row == 6) {
        lineImageView.hidden = NO;
    } else {
        lineImageView.hidden = YES;
    }
}

- (void)setUserInfo:(NSDictionary *)dic
{
    NSString *useravater = [dic objectForKey:@"touxiang"];
    NSString *userName = [dic objectForKey:@"huiyuan"];
    NSString *phone = [dic objectForKey:@"tel"];
    NSString *integration = [dic objectForKey:@"je"];
    
    UILabel *userNameLabel = (UILabel *)[self.contentView viewWithTag:kUSERNAME];
    UILabel *phoneLabel = (UILabel *)[self.contentView viewWithTag:kTEL];
    UILabel *integrationLabel = (UILabel *)[self.contentView viewWithTag:kINTERGRATION];
    UIImageView *avater = (UIImageView *)[self.contentView viewWithTag:kUSERAVATER];

    userNameLabel.text = userName;
    phoneLabel.text = phone;
    integrationLabel.text = integration;
    
    if (![useravater isEqual:[NSNull null]] && useravater.length > 0) {
        NSURL *url = [NSURL URLWithString:useravater];
        [avater setImageWithURL:url];
    } else {
        avater.image = [UIImage imageNamed:@"user_avatar.png"];
    }
}

- (void)setContect:(NSDictionary *)dic
{
    UIImageView *iconIV = (UIImageView *)[self viewWithTag:kICON];
    iconIV.image = [UIImage imageNamed:[dic objectForKey:@"icon"]];
    UILabel *titleLabel = (UILabel *)[self viewWithTag:kLABEL];
    titleLabel.text = [dic objectForKey:@"title"];
    
}

- (void)setViewBorder:(int)row//me
{
    if (row == 0) {
        UIView *view = (UIView *)[self viewWithTag:kMEUSER];
        [view drawBorder];
    }
    
    UIImageView *lineImageView = (UIImageView *)[self viewWithTag:kLINEIMAGE];
    if (row == 6) {
        lineImageView.hidden = NO;
    } else {
        lineImageView.hidden = YES;
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
